package com.cskaoyan.market.service.admin;

import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.db.domain.MarketSearchHistoryExample;
import com.cskaoyan.market.db.mapper.MarketSearchHistoryMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/8 9:18
 */
@Service
public class MarketHistoryServiceImpl implements MarketHistoryService {
    @Autowired
    MarketSearchHistoryMapper marketSearchHistoryMapper;
    @Override
    public List<MarketSearchHistory> listHistory(Integer page, Integer limit, String userId, String keyword, String sort, String order) {
        MarketSearchHistoryExample marketSearchHistoryExample = new MarketSearchHistoryExample();
        marketSearchHistoryExample.setOrderByClause(sort + " " + order);
        MarketSearchHistoryExample.Criteria criteria = marketSearchHistoryExample.createCriteria();
        if (!StringUtils.isEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.valueOf(userId));

        }
        if (!StringUtils.isEmpty(keyword)) {
            criteria.andKeywordLike("%" + keyword + "%");
        }
        PageHelper.startPage(page, limit);
        criteria.andLogicalDeleted(true);

        List<MarketSearchHistory> marketSearchHistoryList = marketSearchHistoryMapper.selectByExampleSelective(marketSearchHistoryExample, MarketSearchHistory.Column.id, MarketSearchHistory.Column.userId, MarketSearchHistory.Column.keyword,
                MarketSearchHistory.Column.addTime, MarketSearchHistory.Column.deleted);
        return marketSearchHistoryList;

    }
}
